package my.mypool.core.memcache;

import my.mypool.core.PoolableParent;

import java.net.Socket;
import java.net.InetSocketAddress;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2010-9-20
 * Time: 16:25:01
 * To change this template use File | Settings | File Templates.
 */
public class PoolableSocket extends PoolableParent {
    private Socket socket=null;
    public void destroy() throws Exception {
        socket.close();
    }

    public boolean validate() {
        return socket.isConnected();
    }

    public void activate() throws Exception {
 
    }

    public void passivate() throws Exception {

    }

    public void init(Object createParam) throws Exception {
        String[] address=((String)createParam).split(":");
        socket=new Socket();
        socket.connect(new InetSocketAddress(address[0],Integer.parseInt(address[1])),10);
    }

    public Socket getSocket(){
        return socket;
    }
}
